//
// Created by gj on 16-2-2.
//

#include "CLog.h"

bool CLogConfig::LOG_ON = true;
bool CLogConfig::LOG_ON_DEFAULT = true;
string CLogConfig::LOG_TAG_DEFAULT("Debug");

//static const CClassInheritInformation CLOG_PRINTER_CLASS_INFORMATION("CLogPrinter", CObject::_class);
//static const CClassInheritInformation CLOG_CLASS_INFOMATION("CLog", CObject::_class);
//
//const CClassInformation *const CLogPrinter::_class = &CLOG_PRINTER_CLASS_INFORMATION;
//const CClassInformation *const CLog::_class = &CLOG_CLASS_INFOMATION;

LOG_FUNCTION_IMPLEMENTATIONS(v, CLogConfig::eLogVerbose)

LOG_FUNCTION_IMPLEMENTATIONS(i, CLogConfig::eLogInfo)

LOG_FUNCTION_IMPLEMENTATIONS(d, CLogConfig::eLogDebug)

LOG_FUNCTION_IMPLEMENTATIONS(w, CLogConfig::eLogWarn)

LOG_FUNCTION_IMPLEMENTATIONS(e, CLogConfig::eLogError)

void CLogAndroidStream::print(CLogConfig::ELogPriority priority, const char *tag, const char *message, va_list &ap) const {
    android_LogPriority android_logPriority;
    switch (priority) {
        case CLogConfig::eLogVerbose:
            android_logPriority = ANDROID_LOG_VERBOSE;
            break;
        case CLogConfig::eLogInfo:
            android_logPriority = ANDROID_LOG_INFO;
            break;
        case CLogConfig::eLogDebug:
            android_logPriority = ANDROID_LOG_DEBUG;
            break;
        case CLogConfig::eLogWarn:
            android_logPriority = ANDROID_LOG_WARN;
            break;
        case CLogConfig::eLogError:
            android_logPriority = ANDROID_LOG_ERROR;
            break;
    }
    __android_log_vprint(android_logPriority, tag, message, ap);
}

CLogAndroidStream CLogPrinter::LOG_DEF_STREAM;

#ifdef FLAG_UNIT_TESTING

static void log_def_unit_testing() {
    LOG_CREATE_FUNC("test")
    LOG_V("printer --> ok")
    LOG_I("printer --> ok")
    LOG_D("printer --> ok")
    LOG_W("printer --> ok")
    LOG_E("printer --> ok")
    LOG_V("printer --> %s", "ok")
    LOG_I("printer --> %s", "ok")
    LOG_D("printer --> %s", "ok")
    LOG_W("printer --> %s", "ok")
    LOG_E("printer --> %s", "ok")

    LOG_V_FUNC("printer --> ok")
    LOG_I_FUNC("printer --> ok")
    LOG_D_FUNC("printer --> ok")
    LOG_W_FUNC("printer --> ok")
    LOG_E_FUNC("printer --> ok")
    LOG_V_FUNC("printer --> %s", "ok")
    LOG_I_FUNC("printer --> %s", "ok")
    LOG_D_FUNC("printer --> %s", "ok")
    LOG_W_FUNC("printer --> %s", "ok")
    LOG_E_FUNC("printer --> %s", "ok")

    LOG_V_FILE_FUNC("printer --> ok")
    LOG_I_FILE_FUNC("printer --> ok")
    LOG_D_FILE_FUNC("printer --> ok")
    LOG_W_FILE_FUNC("printer --> ok")
    LOG_E_FILE_FUNC("printer --> ok")
    LOG_V_FILE_FUNC("printer --> %s", "ok")
    LOG_I_FILE_FUNC("printer --> %s", "ok")
    LOG_D_FILE_FUNC("printer --> %s", "ok")
    LOG_W_FILE_FUNC("printer --> %s", "ok")
    LOG_E_FILE_FUNC("printer --> %s", "ok")
}

static void log_printer_unit_testing() {
    LOG_CREATE_NAME_FUNC(_log, "test")
    LOG_V_NAME(_log, "printer --> name - ok")
    LOG_I_NAME(_log, "printer --> name - ok")
    LOG_D_NAME(_log, "printer --> name - ok")
    LOG_E_NAME(_log, "printer --> name - ok")
    LOG_W_NAME(_log, "printer --> name - ok")
    LOG_V_NAME(_log, "printer --> %s", "name - ok")
    LOG_I_NAME(_log, "printer --> %s", "name - ok")
    LOG_D_NAME(_log, "printer --> %s", "name - ok")
    LOG_E_NAME(_log, "printer --> %s", "name - ok")
    LOG_W_NAME(_log, "printer --> %s", "name - ok")

    LOG_V_NAME_FUNC(_log, "printer --> name - ok")
    LOG_I_NAME_FUNC(_log, "printer --> name - ok")
    LOG_D_NAME_FUNC(_log, "printer --> name - ok")
    LOG_E_NAME_FUNC(_log, "printer --> name - ok")
    LOG_W_NAME_FUNC(_log, "printer --> name - ok")
    LOG_V_NAME_FUNC(_log, "printer --> %s", "name - ok")
    LOG_I_NAME_FUNC(_log, "printer --> %s", "name - ok")
    LOG_D_NAME_FUNC(_log, "printer --> %s", "name - ok")
    LOG_E_NAME_FUNC(_log, "printer --> %s", "name - ok")
    LOG_W_NAME_FUNC(_log, "printer --> %s", "name - ok")

    LOG_V_NAME_FILE_FUNC(_log, "printer --> name - ok")
    LOG_I_NAME_FILE_FUNC(_log, "printer --> name - ok")
    LOG_D_NAME_FILE_FUNC(_log, "printer --> name - ok")
    LOG_E_NAME_FILE_FUNC(_log, "printer --> name - ok")
    LOG_W_NAME_FILE_FUNC(_log, "printer --> name - ok")
    LOG_V_NAME_FILE_FUNC(_log, "printer --> %s", "name - ok")
    LOG_I_NAME_FILE_FUNC(_log, "printer --> %s", "name - ok")
    LOG_D_NAME_FILE_FUNC(_log, "printer --> %s", "name - ok")
    LOG_E_NAME_FILE_FUNC(_log, "printer --> %s", "name - ok")
    LOG_W_NAME_FILE_FUNC(_log, "printer --> %s", "name - ok")
}

static void log_settings_unit_testing() {

}

void log_unit_testing() {
    log_def_unit_testing();
    log_printer_unit_testing();
    log_settings_unit_testing();
}

#endif
